﻿<UserControl x:Class="ImmlPad.DocumentViews.ImmlDocumentView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:c="clr-namespace:ImmlPad.Controls"
  xmlns:a="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  xmlns:settings="clr-namespace:ImmlPad.Properties"
    xmlns:enums="clr-namespace:Imml;assembly=Imml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             x:Name="This"
             Loaded="This_Loaded">
    <UserControl.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/Brushes.xaml" />
                <ResourceDictionary Source="/Resources/PluginTheme.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!--
      *************************************************************************
      Data
      *************************************************************************
      -->
            <c:RowHeightConverter x:Key="_RowHeightConverter" />
            <c:NotConverter x:Key="NotConverter" />
            <c:GreaterThanConverter x:Key="GreaterThanConverter" />
            <BooleanToVisibilityConverter x:Key="_BooleanToVisibilityConverter"/>
            <c:BooleanVisibilityConverter x:Key="_ErrorVisibilityConverter" VisibleOnTrue="False" />
            <!--
      *************************************************************************
      Animations
      *************************************************************************
      -->

            <DoubleAnimation 
        x:Key="ShowErrorOverlay" 
        Storyboard.TargetName="ErrorOverlay" 
        Storyboard.TargetProperty="Opacity"
        To="1"
        Duration="0:0:0.15" />

            <DoubleAnimation 
        x:Key="HideErrorOverlay"
        Storyboard.TargetName="ErrorOverlay" 
        Storyboard.TargetProperty="Opacity"
        Duration="0:0:0.15" />

            <CollectionViewSource x:Key="_SortedItemTypes">
                <CollectionViewSource.SortDescriptions>
                    <scm:SortDescription />
                </CollectionViewSource.SortDescriptions>
                <CollectionViewSource.Source>
                    <ObjectDataProvider MethodName="GetNames" ObjectType="{x:Type sys:Enum}">
                        <ObjectDataProvider.MethodParameters>
                            <x:Type TypeName="enums:ElementType"/>
                        </ObjectDataProvider.MethodParameters>
                    </ObjectDataProvider>
                </CollectionViewSource.Source>
            </CollectionViewSource>
            <DataTemplate x:Key="_ComboDataTemplate">
                <TextBlock Text="{Binding}" TextTrimming="CharacterEllipsis"/>
            </DataTemplate>
            <DataTemplate x:Key="_ComboElementTemplate">
                <TextBlock Text="{Binding Path=Name}" />
            </DataTemplate>
            <CollectionViewSource x:Key="_DocumentElementsViewSource" Source="{Binding Path=Elements}" Filter="_DocumentElementsViewSource_Filter">
                <CollectionViewSource.SortDescriptions>
                    <scm:SortDescription PropertyName="Name" />
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>
        </ResourceDictionary>


    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <!--<RowDefinition Height="Auto" />-->
            <!--<RowDefinition Height="{Binding ElementName=ContentArea, Path=Visibility, Converter={StaticResource _RowHeightConverter}}" />-->
            <!--<RowDefinition Height="Auto" />-->
            <RowDefinition Height="*" />
            <RowDefinition Height="35" />
        </Grid.RowDefinitions>

        <!-- Rendered View -->
        <!--Note: Rendered View temporarily removed-->

        <!--<GridSplitter
      Grid.Row="2"
      Height="6" 
      DragStarted="SplitterDragStarted" 
      DragCompleted="SplitterDragCompleted" 
      ResizeDirection="Rows"
      ResizeBehavior="PreviousAndNext"
      SnapsToDevicePixels="True"
      VerticalAlignment="Bottom"
      HorizontalAlignment="Stretch">
            <GridSplitter.Template>
                <ControlTemplate TargetType="{x:Type GridSplitter}">
                    <Border Background="#20FFFFFF" />
                </ControlTemplate>
            </GridSplitter.Template>
        </GridSplitter>-->

        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition />
            </Grid.RowDefinitions>

            <!--Document navigator-->
            <Grid Background="#20FFFFFF" x:Name="_DocumentNavigatorGrid" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <ComboBox x:Name="_ElementTypeCombo" 
                          Grid.Column="0"
                          Margin="5,5,5,5"
                          DataContext="{StaticResource _SortedItemTypes}" 
                          ItemsSource="{Binding}" 
                          ItemTemplate="{StaticResource _ComboDataTemplate}" 
                          SelectionChanged="_ElementTypeCombo_SelectionChanged"/>

                <ComboBox x:Name="_ElementNameCombo" 
                          Grid.Column="1"
                          Margin="5,5,5,5"
                          ItemsSource="{Binding Source={StaticResource _DocumentElementsViewSource}}" 
                          ItemTemplate="{StaticResource _ComboElementTemplate}"
                          SelectionChanged="_ElementNameCombo_SelectionChanged"
                          PreviewKeyUp="_ElementNameCombo_PreviewKeyUp"/>
            </Grid>
            <c:XmlTextEditor
                Grid.Row="1"
              x:Name="Editor"
              FontFamily="{Binding Source={x:Static settings:Settings.Default}, Path=EditorFontFamily, Mode=TwoWay}"
              FontSize="{Binding Source={x:Static settings:Settings.Default}, Path=EditorFontSize, Mode=TwoWay}"
              ConvertTabs="{Binding Source={x:Static settings:Settings.Default}, Path=ConvertTabs}"
              ConvertTabsCount="{Binding Source={x:Static settings:Settings.Default}, Path=ConvertTabsCount}" 
              ShowLineNumbers="{Binding Source={x:Static settings:Settings.Default}, Path=ShowLineNumbers}" 
              EnableSyntaxHighlighting="{Binding Source={x:Static settings:Settings.Default}, Path=EnableSyntaxHighlighting}" 
              EnableXmlFolding="{Binding Source={x:Static settings:Settings.Default}, Path=EnableXmlFolding}" 
              IsCodeCompletionEnabled="{Binding Source={x:Static settings:Settings.Default}, Path=EnableCodeCompletion}" 
              Text="{Binding Path=SourceText, Mode=TwoWay}"            
              TextChanged="EditorTextChanged" 
                FoldingStatesChanged="Editor_FoldingStatesChanged"/>
        </Grid>

        <!--Status View-->
        <Grid Grid.Row="1">
            <Grid.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="/Resources/PluginTheme.xaml" />
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </Grid.Resources>
            <Grid.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#10FFFFFF" Offset="0" />
                    <GradientStop Color="#00FFFFFF" Offset="1" />
                </LinearGradientBrush>
            </Grid.Background>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Border CornerRadius="0,0,4,0" VerticalAlignment="Bottom" Height="33" BorderBrush="#40FFFFFF" BorderThickness="0,1,0,0" Grid.ColumnSpan="3">

            </Border>

            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="WhiteSmoke">
              Ln 
              <TextBlock Text="{Binding ElementName=This, Path=TextEditor.LineNumber}" Foreground="WhiteSmoke" />,
              Pos
              <TextBlock Text="{Binding ElementName=This, Path=TextEditor.LinePosition}" Foreground="WhiteSmoke"/>
            </TextBlock>

            <!--Error display-->
            <Grid Grid.Column="2" Visibility="{Binding ElementName=This, Path=IsValidMarkup, Converter={StaticResource _ErrorVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <!-- Exclamation -->
                <TextBlock
                        Grid.Column="0"
                        Grid.RowSpan="2"
                        FontWeight="Bold"
                        Foreground="#FFFFBF00"
                        FontFamily="Courier New"
                        FontSize="40"
                        Text="!"
                        Margin="4,0,0,0"/>

                <StackPanel Grid.Column="1" Grid.RowSpan="2" Margin="4,4,4,4">
                    <!-- Error Message -->
                    <TextBlock
                           Margin="0,2,4,0"
                           Foreground="#EEE"
                           TextWrapping="Wrap"
                           Text="{Binding ElementName=This, Path=ErrorText}" />

                    <!-- Line Number -->
                    <Button
                              Margin="0,0,4,4"
                              Foreground="#FFFFBF00"
                              Cursor="Hand"
                              HorizontalAlignment="Left" 
                              Click="LineNumberClick" 
                              MinWidth="0"
                              MinHeight="0">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border Background="Transparent">
                                    <StackPanel Orientation="Horizontal">
                                        <ContentPresenter VerticalAlignment="Center" />
                                        <Path x:Name="Arrow" Fill="White" Margin="8,0,0,0" Stretch="Fill" Opacity="0.2" VerticalAlignment="Center" Width="5" Height="9" Data="M200,200 L200,280 256,240 z"/>
                                    </StackPanel>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter TargetName="Arrow" Property="Opacity" Value="1" />
                                        <Setter TargetName="Arrow" Property="Fill" Value="#FFFFBF00" />
                                    </Trigger>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding ElementName=This, Path=ErrorLineNumber}" Value="0" />
                                            <Condition Binding="{Binding ElementName=This, Path=ErrorLinePosition}" Value="0" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </MultiDataTrigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Button.Template>
                        <TextBlock>
                            Line
                            <TextBlock Text="{Binding ElementName=This, Path=ErrorLineNumber}" />,
                            Position
                            <TextBlock Text="{Binding ElementName=This, Path=ErrorLinePosition}" />
                          </TextBlock>
                    </Button>
                </StackPanel>
            </Grid>
            <!---->
        </Grid>
        
        
    </Grid>
</UserControl>
